﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Subject")]
    public class SubjectInfo : IDetach
    {

        public SubjectInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private int _departid = 0;
        private string _name = "";

        private EntityRef<DepartmentInfo> _departmentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_departmentInfo", ThisKey = "DepartId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public DepartmentInfo DepartmentInfo
        {
            get { return _departmentInfo.Entity; }
            set { _departmentInfo.Entity = value; }
        }

        private EntitySet<ClassInfo> _classInfo;
        [System.Data.Linq.Mapping.Association(Storage = "_classInfo", ThisKey = "Id", OtherKey = "SubjectId")]
        public EntitySet<ClassInfo> ClassInfo
        {
            get { return this._classInfo; }
            set { this._classInfo.Assign(value); }
        }


        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int DepartId
        {
            set { _departid = value; }
            get { return _departid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("专业名称")]
        [Required(ErrorMessage = "必须填写")]
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        #endregion Model

        public void Detach()
        {
            this._departmentInfo = default(EntityRef<DepartmentInfo>);
            this._classInfo = new EntitySet<ClassInfo>();
        }
    }
}
